package com.cskaoyan.market.admin.controller;

import com.cskaoyan.market.admin.service.MarketSearchHistoryService;
import com.cskaoyan.market.admin.service.impl.MarketSearchHistoryServiceImpl;
import com.cskaoyan.market.db.domain.MarketSearchHistory;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author yuanixn2158@163.com
 * @since 2023/05/09 10:46
 */
//http://101.43.69.31:8083/admin/history/list?page=1&limit=20&sort=add_time&order=desc
@RestController
@RequestMapping("/admin/history")
public class AdminSearchHistoryController{
    MarketSearchHistoryService marketSearchHistoryService=new MarketSearchHistoryServiceImpl();

    @RequestMapping("/list")
    protected void list(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer page=Integer.parseInt(req.getParameter("page"));
        Integer limit=Integer.parseInt(req.getParameter("limit"));
        String sort=req.getParameter("sort");
        String order=req.getParameter("order");
        List<MarketSearchHistory>marketSearchHistoryList=marketSearchHistoryService.getSearchHistoryList(page,limit,sort,order);
        Object ok = ResponseUtil.okList(marketSearchHistoryList);
        resp.getWriter().println(JacksonUtil.getObjectMapper().writeValueAsString(ok));
    }
}
